﻿
//
// Copyright (c) 2024 BPer
//
#ifndef SRC_BPERMEETING_INCLUDE_BPerRtcPublish_H_
#define SRC_BPERMEETING_INCLUDE_BPerRtcPublish_H_
#include <bperrtc/BPerPeerConnection2.h>
#include <string>
#include <bperutil/sys/BPerThread2.h>
#include <bperutil/sys/BPerSysMessageI.h>
#include <bperutil/buffer/BPerAudioEncoderBuffer.h>
#include <bperutil/buffer/BPerVideoEncoderBuffer.h>
#include <vector>
using namespace std;
class BPerRtcPublish: public BPerThread {
public:
	BPerRtcPublish(BPerContext *pcontext);
	virtual ~BPerRtcPublish();
        int32_t init(char* url);
	int32_t init(int32_t nettype, char* server, int32_t pport,char* app,char* stream);
	int32_t connectServer(int32_t puid);
	int32_t connectMediaServer();
	int32_t disConnectMediaServer();
	int32_t reconnectMediaServer();
	void setInVideoMetaData(BPerVideoMeta *pvmd);
	void setInAudioList(BPerAudioEncoderBuffer *pbuf);
	void setInVideoList(BPerVideoEncoderBuffer *pbuf);

	int32_t stopPublishAudioData();
	int32_t stopPublishVideoData();

	int32_t publishMsg(BPerFrame* msgFrame);
	int32_t receiveMsg(BPerFrame* msgFrame);
	int32_t m_netState;
	int32_t isPublished;
	int32_t m_isStart;
	void stop();
protected:
	void run();
	void handleError(int32_t perrCode);
	void startLoop();
	void startLoop_h265();
	BPerContext *m_context;
	BPerVideoMeta *m_vmd;
	BPerVideoEncoderBuffer *m_in_videoBuffer;
	BPerAudioEncoderBuffer *m_in_audioBuffer;

	int32_t m_isConvert;
	int32_t m_isInit;
	int32_t m_audioEncoderType;
	std::vector<BPerPeerConnection2*> m_pushs;
private:
	int32_t m_transType;
	int32_t notifyState;
};

#endif /* SRC_BPERMEETING_INCLUDE_BPerRtcPublish_H_ */
